package com.andy.customerService.interceptor;

import com.andy.customerService.entity.JWTUserInfo;
import com.andy.customerService.enums.ExceptionEnum;
import com.andy.customerService.exception.BusinessException;
import com.andy.customerService.utils.JwtUtil;
import com.andy.customerService.utils.UserLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 处理拦截的请求
 */
@Slf4j
public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("preHandle method is running");
  /*      //从头部过去accessToken
        String token = request.getHeader("token");
        //根据token解析对象
        JWTUserInfo jwtUserInfo = JwtUtil.getJWTUserInfoByToken(token);
        if (jwtUserInfo == null) {
            throw new BusinessException(ExceptionEnum.TOKEN_VALIDATE_ERROR);
        }*/
//        JWTUserInfo jwtUserInfo = new JWTUserInfo();
//        jwtUserInfo.setId(1);
//        jwtUserInfo.setLoginName("test");
//        jwtUserInfo.setUserName("test");
//        jwtUserInfo.setTenantId("HQ");
//        UserLocalUtil.setAuthUser(jwtUserInfo);
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        log.debug("postHandle method is running");

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        log.debug("afterCompletion method is running");

    }
}
